/*
 * Relatorios.java
 *
 * Created on 22/02/2010, 10:44:52
 * Copyright Las
 */
package Soligee;

import Soligee.controller.bo.RelatorioControle;
import com.icesoft.faces.component.dragdrop.DragEvent;
import com.icesoft.faces.component.ext.HtmlOutputLabel;
import com.icesoft.faces.component.ext.HtmlOutputText;
import com.icesoft.faces.component.ext.HtmlSelectOneMenu;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectedData;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectionItems;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import javax.faces.FacesException;
import Soligee.view.RequestBean1;
import Soligee.view.Util;
import Soligee.view.ApplicationBean1;
import Soligee.view.SessionBean1;
import javax.faces.component.UISelectItems;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;


/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 */
public class Relatorios extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
    private int __placeholder;

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private DefaultSelectedData selectOneMenu1Bean = new DefaultSelectedData();

    public DefaultSelectedData getSelectOneMenu1Bean() {
        return selectOneMenu1Bean;
    }

    public void setSelectOneMenu1Bean(DefaultSelectedData dsd) {
        this.selectOneMenu1Bean = dsd;
    }
    private DefaultSelectionItems menuSelecao1Items = new DefaultSelectionItems();

    public DefaultSelectionItems getMenuSelecao1Items() {
        return menuSelecao1Items;
    }

    public void setMenuSelecao1Items(DefaultSelectionItems dsi) {
        this.menuSelecao1Items = dsi;
    }
    private DefaultSelectedData selectOneMenu2Bean = new DefaultSelectedData();

    public DefaultSelectedData getSelectOneMenu2Bean() {
        return selectOneMenu2Bean;
    }

    public void setSelectOneMenu2Bean(DefaultSelectedData dsd) {
        this.selectOneMenu2Bean = dsd;
    }
    private DefaultSelectionItems menuSelecao2Items = new DefaultSelectionItems();

    public DefaultSelectionItems getMenuSelecao2Items() {
        return menuSelecao2Items;
    }

    public void setMenuSelecao2Items(DefaultSelectionItems dsi) {
        this.menuSelecao2Items = dsi;
    }
    private DefaultSelectedData selectOneMenu3Bean= new DefaultSelectedData();

    public DefaultSelectedData getSelectOneMenu3Bean() {
        return selectOneMenu3Bean;
    }

    public void setSelectOneMenu3Bean(DefaultSelectedData dsd) {
        this.selectOneMenu3Bean = dsd;
    }
    private DefaultSelectionItems  menuSelecao3Items= new DefaultSelectionItems();

    public DefaultSelectionItems getMenuSelecao3Items() {
        return  menuSelecao3Items;
    }

    public void setMenuSelecao3Items(DefaultSelectionItems dsi) {
        this. menuSelecao3Items= dsi;
    }
    private HtmlSelectOneMenu menuSelecaoRelatorio3 = new HtmlSelectOneMenu();

    public HtmlSelectOneMenu getMenuSelecaoRelatorio3() {
        return menuSelecaoRelatorio3;
    }

    public void setMenuSelecaoRelatorio3(HtmlSelectOneMenu hsom) {
        this.menuSelecaoRelatorio3 = hsom;
    }
    private HtmlSelectOneMenu menuSelecaoRelatorio2 = new HtmlSelectOneMenu();

    public HtmlSelectOneMenu getMenuSelecaoRelatorio2() {
        return menuSelecaoRelatorio2;
    }

    public void setMenuSelecaoRelatorio2(HtmlSelectOneMenu hsom) {
        this.menuSelecaoRelatorio2 = hsom;
    }
    private HtmlSelectOneMenu menuSelecaoRelatorio1 = new HtmlSelectOneMenu();

    public HtmlSelectOneMenu getMenuSelecaoRelatorio1() {
        return menuSelecaoRelatorio1;
    }

    public void setMenuSelecaoRelatorio1(HtmlSelectOneMenu hsom) {
        this.menuSelecaoRelatorio1 = hsom;
    }
    private UISelectItems itemsMenuSelecao1 = new UISelectItems();

    public UISelectItems getItemsMenuSelecao1() {
        return itemsMenuSelecao1;
    }

    public void setItemsMenuSelecao1(UISelectItems uisi) {
        this.itemsMenuSelecao1 = uisi;
    }
    private UISelectItems itemsMenuSelecao2 = new UISelectItems();

    public UISelectItems getItemsMenuSelecao2() {
        return itemsMenuSelecao2;
    }

    public void setItemsMenuSelecao2(UISelectItems uisi) {
        this.itemsMenuSelecao2 = uisi;
    }
    private UISelectItems itemsMenuSelecao3 = new UISelectItems();

    public UISelectItems getItemsMenuSelecao3() {
        return itemsMenuSelecao3;
    }

    public void setItemsMenuSelecao3(UISelectItems uisi) {
        this.itemsMenuSelecao3 = uisi;
    }
    private HtmlOutputText relatorio_tx2 = new HtmlOutputText();

    public HtmlOutputText getRelatorio_tx2() {
        return relatorio_tx2;
    }

    public void setRelatorio_tx2(HtmlOutputText hot) {
        this.relatorio_tx2 = hot;
    }
    private HtmlOutputLabel relatorio_tx3 = new HtmlOutputLabel();

    public HtmlOutputLabel getRelatorio_tx3() {
        return relatorio_tx3;
    }

    public void setRelatorio_tx3(HtmlOutputLabel hol) {
        this.relatorio_tx3 = hol;
    }

    // </editor-fold>
public RelatorioControle ctrRelatorio = new RelatorioControle();
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public Relatorios() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     *
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    //Instacias para criação de relatorio
    /*Relatorio relatorio = new Relatorio();
    ManipulaXML manipulaXML = new ManipulaXML();
    CriaQuery cq = new CriaQuery();
public void criarRelatorio()throws Exception{
    manipulaXML.modificaXML("C:\\Report\\fornecedorContato_relatorio", cq.criaQueryFornecedoresContado());

}
*/

    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
     //Inicializando
      menuSelecao1Items.clear();
      menuSelecao2Items.clear();
      menuSelecao3Items.clear();


      //Add relatorios
         menuSelecao1Items.add(new SelectItem(1,"Clientes"));
         menuSelecao1Items.add(new SelectItem(2,"Fornecedores"));
         menuSelecao1Items.add(new SelectItem(3,"Produtos"));
         menuSelecao1Items.add(new SelectItem(4,"Orçamentos"));
         menuSelecao1Items.add(new SelectItem(5,"Vendas"));



         //Add subSelecao primeiro relatorio da lista

         menuSelecao2Items.add(new SelectItem(1,"Pessoa Fisica"));
          menuSelecao2Items.add(new SelectItem(2," Pessoa Juridica"));

          //Tipo dados primeiro relatório

          menuSelecao3Items.add(new SelectItem(1,"Completo"));
           menuSelecao3Items.add(new SelectItem(2,"Contato"));

//  menuSelecaoRelatorio2.resetValue();
                  //menuSelecaoRelatorio3.


        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here

        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("Relatorios Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }

        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected RequestBean1 getview$RequestBean1() {
        return (RequestBean1) getBean("view$RequestBean1");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected Util getview$Util() {
        return (Util) getBean("view$Util");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected Teste2 getTeste2() {
        return (Teste2) getBean("Teste2");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected ApplicationBean1 getview$ApplicationBean1() {
        return (ApplicationBean1) getBean("view$ApplicationBean1");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected SessionBean1 getview$SessionBean1() {
        return (SessionBean1) getBean("view$SessionBean1");
    }





             public String btn_voltar_action() {


             return "voltar";

    }

    //public String btn_gerarRelatorio_action() {

/*
        try {
             criarRelatorio();
        } catch (Exception e) {
        }

        return null;
    }*/

    public void menuSelecaoRelatorio1_processValueChange(ValueChangeEvent vce) {
  //Cliente
if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString()) == 1){
menuSelecaoRelatorio3.setRendered(true);
relatorio_tx3.setRendered(true);
     relatorio_tx2.setValue("Cliente");

//Add subSelecao primeiro relatorio da lista
           menuSelecao2Items.clear();
           menuSelecao2Items.add(new SelectItem(1,"Pessoa Fisica"));
           menuSelecao2Items.add(new SelectItem(2," Pessoa Juridica"));

          //Tipo dados primeiro relatório
          menuSelecao3Items.clear();
          menuSelecao3Items.add(new SelectItem(1,"Completo"));
          menuSelecao3Items.add(new SelectItem(2,"Contato"));
          relatorio_tx3.setValue("Dados");
}

    if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString()) == 2){
     menuSelecaoRelatorio3.setRendered(false);
      relatorio_tx3.setRendered(false);

      relatorio_tx2.setValue("Dados");
           menuSelecao2Items.clear();
           menuSelecao2Items.add(new SelectItem(1,"Completo"));
           menuSelecao2Items.add(new SelectItem(2," Contato"));

    }

        if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString()) == 3){
 //Add subSelecao primeiro relatorio da lista
           relatorio_tx2.setValue("Produto");
            menuSelecao2Items.clear();
           menuSelecao2Items.add(new SelectItem(7,"Todos"));
             menuSelecao2Items.add(new SelectItem(1," Bebidas"));
           menuSelecao2Items.add(new SelectItem(2," Carnes"));
            menuSelecao2Items.add(new SelectItem(6," Frios/Laticinios"));
             menuSelecao2Items.add(new SelectItem(3," Limpeza"));
              menuSelecao2Items.add(new SelectItem(4," Congelados"));
               menuSelecao2Items.add(new SelectItem(5," Leite/iogurte"));

        menuSelecaoRelatorio3.setRendered(false);
          relatorio_tx3.setRendered(false);

        }

  if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString()) == 4){

      relatorio_tx2.setValue("Cliente");
      relatorio_tx3.setValue("Codigo");
      
      menuSelecao2Items.clear();
      menuSelecao2Items.add(new SelectItem(1," João"));
      menuSelecao2Items.add(new SelectItem(2," Zé"));

      menuSelecao3Items.clear();
      menuSelecao3Items.add(new SelectItem(1," 15"));
      menuSelecao3Items.add(new SelectItem(2," 21"));


      menuSelecaoRelatorio3.setRendered(true);
      relatorio_tx3.setRendered(true);

  }

        System.out.println("trocou para:"+ menuSelecaoRelatorio1.getValue().toString());



    }

    public void painelPrincipal_processMyEvent(DragEvent de) {
    }

    public String btn_gerarRelatorio_action() throws Exception {
       //se igual a 1 entao relatorio de clientes
if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString())== 1){
        System.out.println("#################################################################");
    System.out.println( "RELATORIO ESCOLHIDO:" + "Clientes." );


    //Verifica o tipo de relatorio pessoa juridica ou pessoa fisica
     if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 2){
            System.out.println("SUB SELECAO DO RELATORIO: Pessoa Juridica");


     }
     else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 1)
     System.out.println("SUB SELECAO DO RELATORIO: Pessoa fisica");
        


    //verifica o tipo de relatorio completo ou contato
     if(Integer.parseInt(menuSelecaoRelatorio3.getValue().toString())== 1)
            System.out.println("SUB SELECAO DO RELATORIO: Completo");
    else if(Integer.parseInt(menuSelecaoRelatorio3.getValue().toString())== 2)
            System.out.println("SUB SELECAO DO RELATORIO: Contato");      
    System.out.println("#################################################################");  
        System.out.println("AlterandoXML:");
    ctrRelatorio.relatorioCliente(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString()),Integer.parseInt(menuSelecaoRelatorio3.getValue().toString()));

}

  //se igual a 2 entao relatorio de fornecedor
if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString())== 2){
     System.out.println("#################################################################");
    System.out.println( "RELATORIO ESCOLHIDO:" + "Fornecedor." );

ctrRelatorio.relatoioFornecedor(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString()));


}




//se igual a 3 entao relatorio de Produtos
if(Integer.parseInt(menuSelecaoRelatorio1.getValue().toString())== 3){
     System.out.println("#################################################################");
    System.out.println( "RELATORIO ESCOLHIDO:" + "Produtos." );



    ctrRelatorio.relatorioProdutos(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString()));

   if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 7){
        System.out.println("SUB SELECAO DO RELATORIO: Todos ");
    System.out.println("#################################################################");
   }

    else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 2  ){
        System.out.println("SUB SELECAO DO RELATORIO: Carnes ");
    System.out.println("#################################################################");
    }

    else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 3  ){
        System.out.println("SUB SELECAO DO RELATORIO: Limpeza ");
    System.out.println("#################################################################");
    }

     else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 4  ){
        System.out.println("SUB SELECAO DO RELATORIO: Congelado ");
    System.out.println("#################################################################");
    }

    else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 5  ){
        System.out.println("SUB SELECAO DO RELATORIO:Leite/Iogurte");
    System.out.println("#################################################################");
    }

     else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 6  ){
        System.out.println("SUB SELECAO DO RELATORIO:Frios/Laticinios");
    System.out.println("#################################################################");
    }

     else if(Integer.parseInt(menuSelecaoRelatorio2.getValue().toString())== 1  ){
        System.out.println("SUB SELECAO DO RELATORIO:Bebidas");
    System.out.println("#################################################################");
    }
   


}

      
        return null;
    }



}
